import pandas as pd

# 加载数据集
file_path = r'C:\Users\Administrator\Desktop\python练习\Week Four\titanic.csv'
data = pd.read_csv(file_path)

# 统计乘客人数
total_passengers = data.shape[0]
print(f"乘客总人数: {total_passengers}")

# 统计男、女乘客总人数，统计男比例
gender_counts = data['Sex'].value_counts()
total_male = gender_counts['male']
total_female = gender_counts['female']
male_ratio = total_male / total_passengers
print(f"男乘客人数: {total_male}")
print(f"女乘客人数: {total_female}")
print(f"男乘客比例: {male_ratio:.2%}")

# 计算大于35岁人员姓名
adults_over_35 = data[data['Age'] > 35]['Name']
print("大于35岁人员姓名:")
print(adults_over_35.tolist())

# 计算平均票价
average_fare = data['Fare'].mean()
print(f"平均票价: {average_fare:.2f}")
